package com.itheima.mp.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.mp.domain.po.UserInfoAssignUuid;
import com.itheima.mp.service.IUserInfoAssignUuidService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-12-02
 */
@RestController
@RequestMapping("/user-info-assign-uuid")
public class UserInfoAssignUuidController {

    @Autowired
    private IUserInfoAssignUuidService userInfoService; // 自动装配Service

    // GET请求：获取所有用户信息
    @GetMapping("/list")
    public List<UserInfoAssignUuid> getAllUsers() {
        return userInfoService.list();
    }

    // GET请求：根据ID获取用户信息
    @GetMapping("/{id}")
    public UserInfoAssignUuid getUserById(@PathVariable String id) {
        return userInfoService.getById(id);
    }

    // POST请求：添加用户信息
    @PostMapping("/add")
    public boolean addUser(@RequestBody UserInfoAssignUuid userInfo) {
        return userInfoService.save(userInfo);
    }

    // GET请求：分页查询用户信息
    @GetMapping("/page")
    public Page<UserInfoAssignUuid> getUserPage(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String userName) {
        Page<UserInfoAssignUuid> pageParam = new Page<>(page, size);
        QueryWrapper<UserInfoAssignUuid> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("user_name", userName); // 根据userName模糊查询
        return userInfoService.page(pageParam, queryWrapper);
    }
}
